package codingforgreat.lchot150;

public class Lc036 {
    public boolean isValidSudoku(char[][] board) {
        int N = board.length;
        int M = board[0].length;
        boolean[][] row = new boolean[N][10];//i,j 第i行是否有j数字
        boolean[][] col = new boolean[M][10];//
        boolean[][] slot = new boolean[9][10];
        for(int i = 0;i < 9;i++){
            for(int j = 0;j < 9;j++){
                int s = 3 * (i/3) + (j / 3);
                if(board[i][j] != '.' ){
                    int num = board[i][j] - '0';
                    if(row[i][num] || col[j][num] ||slot[s][num] ){
                        return false;
                    }
                    row[i][num] = true;
                    col[j][num] = true;
                    slot[s][num] = true;
                }
            }
        }
        return true;
    }
}
